<template>
    <div class="app-container">
        <el-card>
            <FormTopBar
                :title="title"
                :flowInsId="form.flowInsId"
                :taskId="taskId"
                :businessId="form.id"
                :billType="billType"
                showSaveAgain="true"
                :readonly="readonly"
                @submitForm="submitForm"
                @submitFormAndSaveAgain="submitFormAndSaveAgain"
            ></FormTopBar>
        </el-card>
        <!-- 添加或修改员工入职对话框 -->
        <el-form
            ref="form"
            :model="form"
            :rules="rules"
            label-width="150px"
            :disabled="readonly"
        >
            <el-card class="box-card top15" style="overflow: visible">
                <div slot="header" class="clearfix"></div>
                <el-row>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
                        <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                            <el-form-item label="姓名">
                                <el-input
                                    disabled
                                    v-model="form.realName"
                                    placeholder="请输入姓名"
                                />
                            </el-form-item>
                        </el-col>
                        <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                            <el-form-item label="工号">
                                <el-input
                                    disabled
                                    v-model="form.staffNum"
                                    placeholder="请输入工号"
                                />
                            </el-form-item>
                        </el-col>
                        <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                            <el-form-item label="部门" prop="deptId">
                                <treeselect
                                    disabled
                                    v-model="form.deptId"
                                    :options="deptOptions"
                                    :show-count="true"
                                    placeholder="请选择归属部门"
                                />
                            </el-form-item>
                        </el-col>

                        <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                            <el-form-item label="岗位类别">
                                <el-select
                                    disabled
                                    v-model="form.postTypeCode"
                                    placeholder="请选择"
                                    @change="getPostList()"
                                >
                                    <el-option
                                        v-for="dict in dict.type.job_category"
                                        :key="dict.value"
                                        :label="dict.label"
                                        :value="dict.value"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>

                        <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                            <el-form-item label="岗位名称" prop="postId">
                                <el-select
                                    disabled
                                    v-model="form.postId"
                                    placeholder="请先选择岗位类别"
                                >
                                    <el-option
                                        v-for="item in postList"
                                        :key="item.postId"
                                        :label="item.postName"
                                        :value="item.postId"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                            <el-form-item
                                label="转正日期"
                                prop="toformalTime"
                                :rules="
                                    !$route.query.toformal
                                        ? []
                                        : [
                                              {
                                                  required: true,
                                                  message: '请选择转正日期',
                                                  trigger: 'change',
                                              },
                                          ]
                                "
                            >
                                <el-date-picker
                                    clearable
                                    v-model="form.toformalTime"
                                    type="date"
                                    value-format="yyyy-MM-dd"
                                ></el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                            <el-form-item
                                label="员工状态"
                                :prop="readonly ? '' : 'staffType'"
                            >
                                <el-select
                                    :disabled="$route.query.toformal == 1"
                                    v-model="form.staffType"
                                    placeholder="请选择"
                                >
                                    <el-option
                                        v-for="dict in dict.type.hrm_staff_type"
                                        :key="dict.value"
                                        :label="dict.label"
                                        :value="dict.value"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                            <el-form-item
                                label="工作业绩"
                                prop="exGzyj"
                                :rules="[
                                    {
                                        max: 100,
                                        message: '工作业绩最多为100个字符',
                                        trigger: 'blur',
                                    },
                                ]"
                            >
                                <el-input
                                    v-model="form.exGzyj"
                                    type="textarea"
                                    :rows="5"
                                    placeholder=""
                                />
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                            <el-form-item
                                label="工作内容"
                                prop="exGznr"
                                :rules="[
                                    {
                                        max: 100,
                                        message: '工作内容最多为100个字符',
                                        trigger: 'blur',
                                    },
                                ]"
                            >
                                <el-input
                                    v-model="form.exGznr"
                                    type="textarea"
                                    :rows="5"
                                    placeholder=""
                                />
                            </el-form-item>
                        </el-col>

                        <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                            <el-form-item
                                v-show="false"
                                label="性别"
                                prop="sex"
                            >
                                <!-- <el-radio-group v-model="form.sex">
                                    <el-radio
                                        v-for="dict in dict.type.sys_user_sex"
                                        :key="dict.value"
                                        :label="dict.value"
                                        >{{ dict.label }}
                                    </el-radio>
                                </el-radio-group> -->
                                <el-select
                                    v-model="form.sex"
                                    placeholder="请选择"
                                >
                                    <el-option
                                        v-for="dict in dict.type.sys_user_sex"
                                        :key="dict.value"
                                        :label="dict.label"
                                        :value="dict.value"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                            <el-form-item
                                v-show="false"
                                label="民族"
                                prop="nation"
                            >
                                <el-select
                                    v-model="form.nation"
                                    placeholder="请选择"
                                >
                                    <el-option
                                        v-for="dict in dict.type.nation_list"
                                        :key="dict.value"
                                        :label="dict.label"
                                        :value="dict.value"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                            <el-form-item
                                v-show="false"
                                label="身份证号"
                                prop="idNum"
                            >
                                <el-input
                                    v-model="form.idNum"
                                    @blur="setBirthdate"
                                />
                            </el-form-item>
                        </el-col>
                        <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                            <el-form-item
                                v-show="false"
                                label="出生日期"
                                prop="birthdate"
                            >
                                <el-date-picker
                                    clearable
                                    v-model="form.birthdate"
                                    type="date"
                                    value-format="yyyy-MM-dd"
                                ></el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                            <el-form-item
                                v-show="false"
                                label="年龄"
                                prop="age"
                            >
                                <el-input v-model="form.age"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                            <el-form-item
                                v-show="false"
                                label="政治面貌"
                                prop="political"
                            >
                                <el-select
                                    v-model="form.political"
                                    placeholder="请选择"
                                >
                                    <el-option
                                        v-for="dict in dict.type
                                            .political_status"
                                        :key="dict.value"
                                        :label="dict.label"
                                        :value="dict.value"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>

                        <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                            <el-form-item
                                v-show="false"
                                label="入党(团)时间"
                                prop="joinpartyDate"
                            >
                                <el-date-picker
                                    clearable
                                    v-model="form.joinpartyDate"
                                    type="date"
                                    value-format="yyyy-MM-dd"
                                ></el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                            <el-form-item
                                v-show="false"
                                label="籍贯"
                                prop="nativePlace"
                            >
                                <el-cascader
                                    :options="options"
                                    placeholder="省/地市/区"
                                    style="width: 100%"
                                    :props="{
                                        value: 'name',
                                        label: 'name',
                                        children: 'areas',
                                    }"
                                    v-model="areaArr"
                                    @change="setAreaForm"
                                >
                                </el-cascader>
                            </el-form-item>
                        </el-col>

                        <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                            <el-form-item
                                v-show="false"
                                label="手机号"
                                prop="phone"
                            >
                                <el-input v-model="form.phone" />
                            </el-form-item>
                        </el-col>

                        <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                            <el-form-item
                                v-show="false"
                                label="电子邮箱"
                                prop="mail"
                            >
                                <el-input
                                    v-model="form.mail"
                                    placeholder="请输入邮箱"
                                />
                            </el-form-item>
                        </el-col>
                        <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                            <el-form-item
                                v-show="false"
                                label="联系人"
                                prop="urgentContact"
                            >
                                <el-input
                                    v-model="form.urgentContact"
                                    placeholder="请输入联系人"
                                />
                            </el-form-item>
                        </el-col>
                        <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                            <el-form-item
                                v-show="false"
                                label="家庭住址"
                                prop="homeAddress"
                            >
                                <el-input
                                    v-model="form.homeAddress"
                                    placeholder="请输入家庭住址"
                                />
                            </el-form-item>
                        </el-col>
                        <!-- <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                                <el-form-item  v-show="false" label="联系地址" prop="urgentContactAddress">
                                    <el-input v-model="form.urgentContactAddress" placeholder="请输入紧急联系人地址"/>
                                </el-form-item>
                            </el-col> -->

                        <!-- <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                            <el-form-item  v-show="false" label="转正日期" prop="toformalTime">
                                <el-date-picker clearable v-model="form.toformalTime" type="date" value-format="yyyy-MM-dd"
                                                placeholder="请选择转正日期"></el-date-picker>
                            </el-form-item>
                        </el-col> -->
                    </el-col>
                </el-row>
            </el-card>
            <el-card
                v-show="false"
                class="box-card top15"
                style="overflow: visible"
            >
                <div slot="header" class="clearfix">
                    <span>拓展信息</span>
                </div>
                <el-row>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
                        <el-col
                            v-show="form.staffType == 0"
                            :xs="11"
                            :sm="11"
                            :md="11"
                            :lg="11"
                            :xl="11"
                        >
                            <el-form-item
                                label="实习时长"
                                prop="probationPeriod"
                            >
                                <el-select
                                    v-model="form.probationPeriod"
                                    placeholder="请选择"
                                    clearable
                                >
                                    <el-option
                                        v-for="dict in internshipDurationDict"
                                        :key="dict.value"
                                        :label="dict.label"
                                        :value="dict.value"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>

                        <!-- <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                            <el-form-item  v-show="false" label="工号" prop="staffNum">
                                <el-input v-model="form.staffNum" />
                            </el-form-item>
                        </el-col> -->
                        <!-- <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                            <el-form-item  v-show="false" label="工资编号" prop="wageNumber">
                                <el-input v-model="form.wageNumber" />
                            </el-form-item>
                        </el-col> -->

                        <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                            <el-form-item
                                v-show="false"
                                label="入职日期"
                                prop="entryTime"
                            >
                                <el-date-picker
                                    clearable
                                    v-model="form.entryTime"
                                    type="date"
                                    value-format="yyyy-MM-dd"
                                    placeholder="请选择入职日期"
                                ></el-date-picker>
                            </el-form-item>
                        </el-col>

                        <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                            <el-form-item
                                v-show="false"
                                label="备注"
                                prop="remark"
                            >
                                <el-input
                                    type="textarea"
                                    :rows="3"
                                    placeholder="请输入内容"
                                    v-model="form.remark"
                                >
                                </el-input>
                            </el-form-item>
                        </el-col>
                    </el-col>
                </el-row>
            </el-card>
            <el-card
                v-show="false"
                class="box-card top15"
                style="overflow: visible"
            >
                <div slot="header" class="clearfix">
                    <span>教育经历</span>
                </div>
                <el-row>
                    <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                        <el-form-item
                            v-show="false"
                            label="教育经历"
                            prop="education"
                        >
                            <el-select
                                v-model="form.education"
                                placeholder="请选择民族"
                            >
                                <el-option
                                    v-for="dict in dict.type.education_list"
                                    :key="dict.value"
                                    :label="dict.label"
                                    :value="dict.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>

                    <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                        <el-form-item
                            v-show="false"
                            label="教育经历取得时间"
                            prop="endDate"
                        >
                            <el-date-picker
                                clearable
                                v-model="form.endDate"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择教育经历取得时间"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                        <el-form-item
                            v-show="false"
                            label="毕业院校"
                            prop="毕业院校"
                        >
                            <el-input
                                v-model="form.schoolName"
                                placeholder="请输入"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                        <el-form-item
                            v-show="false"
                            label="专业"
                            prop="major"
                            width="150"
                        >
                            <el-input
                                v-model="form.major"
                                placeholder="请输入专业"
                            />
                        </el-form-item>
                    </el-col>

                    <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                        <el-form-item
                            v-show="false"
                            label="学制（教育经历）"
                            prop="drgree"
                        >
                            <el-select
                                v-model="form.drgree"
                                placeholder="请选择"
                            >
                                <el-option
                                    v-for="dict in dict.type.educational_system"
                                    :key="dict.value"
                                    :label="dict.label"
                                    :value="dict.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>

                    <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                        <el-form-item
                            v-show="false"
                            label="最高学位"
                            prop="degree"
                        >
                            <el-select
                                v-model="form.degree"
                                placeholder="请选择民族"
                            >
                                <el-option
                                    v-for="dict in dict.type.degree_value"
                                    :key="dict.value"
                                    :label="dict.label"
                                    :value="dict.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="11" :sm="11" :md="11" :lg="11" :xl="11">
                        <el-form-item
                            v-show="false"
                            label="最高学位取得时间"
                            prop="endDate"
                        >
                            <el-date-picker
                                clearable
                                v-model="form.endDate"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择最高学位取得时间"
                            />
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-card>
        </el-form>
    </div>
</template>

<script>
import {
    listInduction,
    getInduction,
    delInduction,
    addInduction,
    updateInduction,
} from "@/api/hrm/staff/induction";
import BillType from "@/billType";
import FlowInfo from "@/views/workflow/flow/flowInfo";
import { treeselect } from "@/api/system/dept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
// import { listPost } from "@/api/system/post";
import { listPost } from "@/api/system/post";
import { queryAll } from "@/api/area";

import FormTopBar from "@/views/workflow/common/formTopBar";
// 地区文件
import pcas from "@/assets/pcas-code.json";
import { del } from "vue";
const defaultForm = {
    sex: "0",
    staffType: "0",
};
export default {
    name: "StaffInductionForm",
    dicts: [
        "political_status",
        "education_list",
        "sys_yes_no",
        "family_relation_type",
        "nation_list",
        "marry_status",
        "language_level",
        "sys_user_sex",
        "driverslicense_type",
        "hrm_staff_type",
        "job_category",
        "educational_system",
        "degree_value",
    ],

    components: { FlowInfo, Treeselect, FormTopBar },
    data() {
        return {
            showFlowInfo: false,
            taskId: "",
            showCommitDialog: false,
            commitType: "",
            billType: BillType.billType.STAFF_INDUCTION,
            // 部门树选项
            deptOptions: [],
            // 职位----选择的职位
            postIds: [],
            //选择的驾照类型
            driverslicenseList: [],
            // 职位选项
            postList: [],
            // 子表选中数据
            checkedPlStaffInductionEduexp: [],
            // 子表选中数据
            checkedPlStaffInductionFamily: [],
            // 子表选中数据
            checkedPlStaffInductionWorkexp: [],
            // 员工入职表格数据
            inductionList: [],
            // 员工入职信息登记--教育经历表格数据
            staffInductionEduexpList: [],
            // 员工入职信息登记--家庭成员表格数据
            staffInductionFamilyList: [],
            // 员工入职信息登记--工作经历表格数据
            staffInductionWorkexpList: [],
            // 表单参数
            form: {
                ...defaultForm,
            },
            // 表单校验
            rules: {
                schoolName: [
                    {
                        required: true,
                        message: "毕业院校不能为空",
                        trigger: "blur",
                    },
                    {
                        max: 32,
                        message: "毕业院校长度不超过32个字符",
                        trigger: "blur",
                    },
                ],
                remark: [
                    {
                        max: 60,
                        message: "备注长度不超过60个字符",
                        trigger: "blur",
                    },
                ],
                postTypeCode: [
                    {
                        required: true,
                        message: "请选择岗位类别",
                        trigger: "change",
                    },
                ],
                wageNumber: [
                    {
                        required: true,
                        message: "工资编号不能为空",
                        trigger: "blur",
                    },
                    {
                        max: 32,
                        message: "工资编号长度不超过32个字符",
                        trigger: "blur",
                    },
                ],
                staffNum: [
                    {
                        required: true,
                        message: "工号不能为空",
                        trigger: "blur",
                    },
                    {
                        max: 32,
                        message: "工号长度不超过32个字符",
                        trigger: "blur",
                    },
                ],
                homeAddress: [
                    {
                        max: 50,
                        message: "家庭住址长度不超过50个字符",
                        trigger: "blur",
                    },
                ],
                realName: [
                    {
                        required: true,
                        message: "姓名不能为空",
                        trigger: "blur",
                    },
                    {
                        max: 50,
                        message: "姓名长度不超过50个字符",
                        trigger: "blur",
                    },
                ],
                orgId: [
                    {
                        required: true,
                        message: "归属部门为空",
                        trigger: "change",
                    },
                ],
                political: [
                    {
                        required: true,
                        message: "政治面貌不能为空",
                        trigger: "change",
                    },
                ],
                sex: [
                    {
                        required: true,
                        message: "性别不能为空",
                        trigger: "blur",
                    },
                ],
                education: [
                    {
                        required: true,
                        message: "请选择教育经历",
                        trigger: "change",
                    },
                ],
                height: [
                    {
                        type: "number",
                        message: "请输入数字（单位厘米cm）",
                        trigger: "blur",
                        transform: (value) => {
                            value = (value + "").replace(/(^\s*)|(\s*$)/g, ""); // 先去除前后空格
                            return value || value === 0 ? Number(value) : 0; // 转为数字
                        },
                    },
                ],
                weight: [
                    {
                        type: "number",
                        message: "请输入数字（单位公斤kg）",
                        trigger: "blur",
                        transform: (value) => {
                            value = (value + "").replace(/(^\s*)|(\s*$)/g, ""); // 先去除前后空格
                            return value || value === 0 ? Number(value) : 0; // 转为数字
                        },
                    },
                ],
                nation: [
                    {
                        required: true,
                        message: "民族不能为空",
                        trigger: "change",
                    },
                ],
                birthdate: [
                    {
                        required: true,
                        message: "出生日期不能为空",
                        trigger: "blur",
                    },
                ],
                entryTime: [
                    {
                        required: true,
                        message: "入职日期不能为空",
                        trigger: "blur",
                    },
                ],
                political: [
                    {
                        required: true,
                        message: "政治面貌不能为空",
                        trigger: "blur",
                    },
                ],
                // marryStatus: [
                //     {required: true, message: "婚姻状况不能为空", trigger: "blur"}
                // ],
                // nativePlace: [
                //     {required: true, message: "籍贯不能为空", trigger: "blur"}
                // ],
                idNum: [
                    {
                        required: true,
                        message: "身份证号不能为空",
                        trigger: "blur",
                    },
                ],
                phone: [
                    {
                        required: true,
                        message: "手机号不能为空",
                        trigger: "blur",
                    },
                    {
                        pattern: /^1[3456789]\d{9}$/,
                        message: "请输入正确的手机号",
                        trigger: "blur",
                    },
                ],
                mail: [
                    {
                        max: 20,
                        message: "邮箱长度不超过20个字符",
                        trigger: "blur",
                    },
                ],
                // nowAddress: [
                //     {required: true, message: "现居住地不能为空", trigger: "blur"}
                // ],
                urgentContact: [
                    {
                        max: 20,
                        message: "联系人字符长度不超过20个字符",
                        trigger: "blur",
                    },
                ],
                // urgentContactRel: [
                //     {required: true, message: "紧急联系人关系不能为空", trigger: "blur"}
                // ],
                // urgentContactAddress: [
                // { max: 50, message: "家庭住址字符长度不超过20个字符", trigger: "blur"},
                // ],
                // urgentContactPhone: [
                //     {required: true, message: "紧急联系人电话不能为空", trigger: "blur"}
                // ],
                staffType: [
                    {
                        required: true,
                        message: "编制类型不能为空",
                        trigger: "blur",
                    },
                ],
            },
            readonly: false,
            options: [],
            areaArr: [],
            internshipDurationDict: [
                {
                    label: "1个月",
                    value: 1,
                },
                {
                    label: "2个月",
                    value: 2,
                },
                {
                    label: "3个月",
                    value: 3,
                },
                {
                    label: "4个月",
                    value: 4,
                },
                {
                    label: "5个月",
                    value: 5,
                },

                {
                    label: "6个月",
                    value: 6,
                },
            ],
            tempStaffType: null, //临时员工状态
        };
    },
    provide() {
        return {
            addCcedList: this.addCcedList,
        };
    },
    computed: {
        title() {
            return this.readonly
                ? "查看转正信息"
                : this.$route.query.toformal
                ? "转正信息"
                : "编辑转正信息";
        },
    },
    created() {
        //菜单传进来的参数
        const readonly = this.$route.query && this.$route.query.readonly;
        const formId = this.$route.params && this.$route.params.formId;
        const taskId = this.$route.query && this.$route.query.taskId;

        if (taskId) {
            this.taskId = taskId;
        }
        if (formId) {
            this.form.id = formId;
            this.getDetailData(formId);
        }
        console.log("readonly:" + readonly);
        if ("1" == readonly) {
            this.readonly = true;
        }

        // 查询省市区
        this.getAreaData();

        //查询基础数据
        this.getTreeselect();
        // this.getPostList();
    },
    mounted() {
        console.log(this.dict.type.driverslicense_type);
    },
    methods: {
        getAreaData() {
            queryAll().then((response) => {
                this.options = response.data;
            });
        },
        /**
         * 设置市区街道数据
         */
        setAreaForm(areaArr) {
            console.log(areaArr, "areaArr");
            this.form.nativePlace = "";

            if (areaArr && areaArr.length > 0) {
                areaArr.forEach((areaName, index) => {
                    if (index == 0) {
                        this.form.nativePlace = areaName;
                    } else {
                        this.form.nativePlace =
                            this.form.nativePlace + "/" + areaName;
                    }
                });
            }
        },

        /**根据身份证号设置生日 */
        setBirthdate() {
            if (this.form.idNum) {
                /**从身份证号中解析出出生日期(2020-05-05)*/
                const year = this.form.idNum.substring(6, 10);
                const month = this.form.idNum.substring(10, 11);
                const day = this.form.idNum.substring(11, 14);
                this.$set(
                    this.form,
                    "birthdate",
                    year + "-" + month + "-" + day
                );
                /**从年龄=当前日期-出生日期=N年M月（M＜11），年龄=N*/
                const now = new Date();
                const year1 = now.getFullYear();
                const month1 = now.getMonth();
                const day1 = now.getDate();
                const age = year1 - year;
                if (month1 < month) {
                    age--;
                }
                this.$set(this.form, "age", age);
            }
        },

        /** 查询部门下拉树结构 */
        getTreeselect() {
            treeselect().then((response) => {
                this.deptOptions = response.data;
            });
        },
        getPostList() {
            //清空岗位名称

            this.postIds = [];
            listPost({
                pageSize: 100,
                postTypeCode: this.form.postTypeCode,
            }).then((res) => {
                this.postList = res.rows;
            });
        },
        //  获取单据信息
        getDetailData(id) {
            getInduction(id).then((response) => {
                let tempObj = response.data;
                console.log(this.$route.query.toformal, "路由");

                console.log(tempObj, "tempObj");
                this.form = tempObj;
                //当状态位转正时
                if (this.$route.query.toformal) {
                    // 开启bug46
                    if (this.$store.getters.allDefectObj["HR-WEB-046"] == 0) {
                        this.tempStaffType = response.data.staffType;
                    }

                    //转正时间为当前时间
                    this.form.toformalTime = new Date();
                    this.form.staffType = "1"; //状态改了
                }
                this.form.billType = this.billType;
                //驾照类型
                if (
                    this.form.driverslicenseType &&
                    this.form.driverslicenseType.length > 0
                ) {
                    this.driverslicenseList =
                        this.form.driverslicenseType.split(",");
                }
                //岗位
                if (this.form.postTypeCode) {
                    this.getPostList();
                }
                console.log(this.form.postId);
                console.log(this.form.postId && this.form.postId.length > 0);

                if (this.form.nativePlace) {
                    let areaArr = this.form.nativePlace.split("/");
                    if (areaArr.length > 0) {
                        this.areaArr = areaArr;
                    }
                }

                this.form.postId = Number(this.form.postId);

                this.staffInductionEduexpList =
                    response.data.staffInductionEduexpList;
                this.staffInductionFamilyList =
                    response.data.staffInductionFamilyList;
                this.staffInductionWorkexpList =
                    response.data.staffInductionWorkexpList;
            });
        },
        /** 提交按钮 */
        submitForm() {
            this.$refs["form"].validate((valid) => {
                if (valid) {
                    if (
                        this.driverslicenseList &&
                        this.driverslicenseList.length > 0
                    ) {
                        this.form.driverslicenseType =
                            this.driverslicenseList.join(",");
                    }

                    this.form.staffInductionEduexpList =
                        this.staffInductionEduexpList;
                    this.form.staffInductionFamilyList =
                        this.staffInductionFamilyList;
                    this.form.staffInductionWorkexpList =
                        this.staffInductionWorkexpList;
                    if (this.$route.query.toformal) {
                        if (
                            this.$store.getters.allDefectObj["HR-WEB-046"] == 0
                        ) {
                            this.form.staffType = this.tempStaffType;
                        }
                    }

                    if (this.form.id != null) {
                        updateInduction(this.form).then((response) => {
                            this.$modal.msgSuccess("修改成功");
                            this.closeThisPage();
                        });
                    } else {
                        addInduction(this.form).then((response) => {
                            this.$modal.msgSuccess("新增成功");
                            this.closeThisPage();
                        });
                    }
                }
            });
        },
        submitFormAndSaveAgain() {
            this.$refs["form"].validate((valid) => {
                if (valid) {
                    if (
                        this.driverslicenseList &&
                        this.driverslicenseList.length > 0
                    ) {
                        this.form.driverslicenseType =
                            this.driverslicenseList.join(",");
                    }

                    if (this.postIds && this.postIds.length > 0) {
                        this.form.postId = this.postIds.join(",");
                    }
                    this.form.staffInductionEduexpList =
                        this.staffInductionEduexpList;
                    this.form.staffInductionFamilyList =
                        this.staffInductionFamilyList;
                    this.form.staffInductionWorkexpList =
                        this.staffInductionWorkexpList;
                    if (this.form.id != null) {
                        updateInduction(this.form).then((response) => {
                            this.$modal.msgSuccess("修改成功");
                            this.resetThisPage();
                        });
                    } else {
                        addInduction(this.form).then((response) => {
                            this.$modal.msgSuccess("新增成功");
                            this.resetThisPage();
                        });
                    }
                }
            });
        },

        closeThisPage() {
            // const obj = { path: "/hrm/staff/induction" };
            // this.$tab.closeOpenPage(obj);
            this.$router.go(-1);
        },
        resetThisPage() {
            this.form = { ...defaultForm };
            this.$refs["form"].resetFields();
        },
        /** 教育经历序号 */
        rowPlStaffInductionEduexpIndex({ row, rowIndex }) {
            row.index = rowIndex + 1;
        },
        /** 家庭成员序号 */
        rowPlStaffInductionFamilyIndex({ row, rowIndex }) {
            row.index = rowIndex + 1;
        },
        /** 工作经历序号 */
        rowPlStaffInductionWorkexpIndex({ row, rowIndex }) {
            row.index = rowIndex + 1;
        },
        /** 教育经历添加按钮操作 */
        handleAddPlStaffInductionEduexp() {
            let obj = {};
            obj.remark = "";
            obj.schoolName = "";
            obj.schoolAddress = "";
            obj.isAllday = "";
            obj.major = "";
            obj.education = "";
            obj.startDate = "";
            obj.endDate = "";
            this.staffInductionEduexpList.push(obj);
        },
        /** 家庭成员信息添加 */
        handleAddPlStaffInductionFamily() {
            let obj = {};
            obj.remark = "";
            obj.name = "";
            obj.birthdate = "";
            obj.age = "";
            obj.political = "";
            obj.company = "";
            obj.position = "";
            obj.phone = "";
            obj.relation = "";
            this.staffInductionFamilyList.push(obj);
        },
        /** 工作经历信息添加 */
        handleAddPlStaffInductionWorkexp() {
            let obj = {};
            obj.remark = "";
            obj.companyName = "";
            obj.companyAddress = "";
            obj.companyDept = "";
            obj.position = "";
            obj.witness = "";
            obj.witnessPhone = "";
            this.staffInductionWorkexpList.push(obj);
        },
        /** 教育经历删除按钮操作 */
        handleDeletePlStaffInductionEduexp() {
            if (this.checkedPlStaffInductionEduexp.length == 0) {
                this.$modal.msgError("请先选择要删除的教育经历信息");
            } else {
                const staffInductionEduexpList = this.staffInductionEduexpList;
                const checkedPlStaffInductionEduexp =
                    this.checkedPlStaffInductionEduexp;
                this.staffInductionEduexpList = staffInductionEduexpList.filter(
                    function (item) {
                        return (
                            checkedPlStaffInductionEduexp.indexOf(item.index) ==
                            -1
                        );
                    }
                );
            }
        },
        /** 家庭成员删除按钮操作 */
        handleDeletePlStaffInductionFamily() {
            if (this.checkedPlStaffInductionFamily.length == 0) {
                this.$modal.msgError("请先选择要删除的家庭成员信息");
            } else {
                const staffInductionFamilyList = this.staffInductionFamilyList;
                const checkedPlStaffInductionFamily =
                    this.checkedPlStaffInductionFamily;
                this.staffInductionFamilyList = staffInductionFamilyList.filter(
                    function (item) {
                        return (
                            checkedPlStaffInductionFamily.indexOf(item.index) ==
                            -1
                        );
                    }
                );
            }
        },
        /** 工作经历删除按钮操作 */
        handleDeletePlStaffInductionWorkexp() {
            if (this.checkedPlStaffInductionWorkexp.length == 0) {
                this.$modal.msgError("请先选择要删除的工作经历");
            } else {
                const staffInductionWorkexpList =
                    this.staffInductionWorkexpList;
                const checkedPlStaffInductionWorkexp =
                    this.checkedPlStaffInductionWorkexp;
                this.staffInductionWorkexpList =
                    staffInductionWorkexpList.filter(function (item) {
                        return (
                            checkedPlStaffInductionWorkexp.indexOf(
                                item.index
                            ) == -1
                        );
                    });
            }
        },
        /** 复选框选中数据 */
        handlePlStaffInductionEduexpSelectionChange(selection) {
            this.checkedPlStaffInductionEduexp = selection.map(
                (item) => item.index
            );
        },
        /** 复选框选中数据 */
        handlePlStaffInductionFamilySelectionChange(selection) {
            this.checkedPlStaffInductionFamily = selection.map(
                (item) => item.index
            );
        },
        /** 复选框选中数据 */
        handlePlStaffInductionWorkexpSelectionChange(selection) {
            this.checkedPlStaffInductionWorkexp = selection.map(
                (item) => item.index
            );
        },
        // 创建单据时候，选择了抄送人
        addCcedList(ccedList) {
            this.form.ccedList = ccedList;
            console.log("回填抄送人");
            console.log(this.form);
        },
    },
};
</script>
<style scoped>
/deep/.vue-treeselect__input-container input {
    display: block;
}
</style>
<style scoped lang="scss"></style>
